package leetcode;

import java.util.Objects;

/**
 * @author ht
 * @create 2025-07-09 22:55
 * @desc
 **/
public class T151 {

    public static void main(String[] args) {
        System.out.println(reverseWords("  hello world  "));
    }

    public static String reverseWords(String s) {
        String[] list = s.split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = list.length - 1; i >= 0; i--) {
            String str = list[i];
            if(!Objects.equals(str, "")) {
                sb.append(str);
                sb.append(" ");
            }
        }
        sb.deleteCharAt(sb.length() -1);
        return sb.toString();
    }
}
